<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>


<script type="text/javascript">
    //分页 js
    $(function () {
//选择table的id.datagrid控件
        $("#table1").datagrid({
            url: "${pageContext.request.contextPath}/fya",
//是否显示分页
            pagination: true,
            toolbar: "#del2",
//标题信息
            fit: true,
            title: "用户信息表",
            //width: 499,
            //height: 339,
//显示数据
            columns: [[

                {checkbox: true},
                {field: 'articleId', title: '文章编号'},
                {field: 'articleName', title: '文章名称'},

                {
                    field: 'articleImage', title: '文章封面', formatter: function (value, rowData, rowIndex) {

                        if (value != undefined) {
                            var tp = "<img src='${pageContext.request.contextPath}" + value + "'>";
                            console.info(tp);
                            return tp;
                        }
                        console.info(value);


                    }
                },
                {field: 'articleContent', title: '文章内容简介'},
                {field: 'guruId', title: '所属上师id'},

                {field: 'articleDate', title: '时间'},
            ]],

        });


        $("#insert1").dialog({

            title: "添加",
            closed: true,
            width: 300,
            height: 300,
        });

    });

    function tj1() {
        $("#insert1").window("open");
    }


    function jd1() {
        var de = $("#table1").datagrid("getSelections");
        if (de.length == 0) {
            $.messager.alert('我的消息', '亲,您什么都没有选中哦！', 'warning');
        } else {

            $.messager.confirm('我的消息', '亲,确定要删除此文章吗！', function (s) {
                if (s) {

                    var id = new Array();

                    for (var i = 0; i < de.length; i++) {
                        //           实体类id
                        id[i] = de[i].articleId;
                    }
                    //alert(id);
                    $.ajax({
                        url: "${pageContext.request.contextPath}/deletea",
                        //    controller收参id
                        data: "id=" + id,
                        type: "post",
                        success: function (m) {
                            if (m.mydeleteaa) {
                                $("#table1").datagrid("load");
                                $.messager.alert('我的消息', '删除成功！', 'info');
                            } else {
                                $.messager.alert('我的消息', '失败,请重试！', 'info');
                            }

                        }
                    });
                }

            });

        }
    }

    function tijiao2() {
        var image = $("#image").val();
        var name = $("#name").val();
        var content = $("#content").val();
        var guruid = $("#guruid").val();


        $.ajax({
            url: "${pageContext.request.contextPath}/inserta",
            data: {"articleImage": image, "articleName": name, "articleContent": content,"guruId":guruid},
            dataType: "json",
            type: "post",
            async: false,
            success: function (s) {
                if (s.myinserta) {
                    //alert(s.myinsert);
                    $("#insert1").window("close");
                    $("#table1").datagrid("load");
                    $.messager.alert('我的消息', '添加成功！', 'info');
                } else {
                    $.messager.alert('我的消息', '添加失败！', 'info');
                }
            }
        });
    }
</script>
<table id="table1"></table>

<div id="del2">
    <%--<a id="dj" class="easyui-linkbutton" onclick="dj()">冻结</a>--%>
    <a id="jd" class="easyui-linkbutton" onclick="jd1()">删除</a>
    <a id="tj" class="easyui-linkbutton" onclick="tj1()">添加</a>
</div>

<div id="insert1">

    文章名称:<input type="text" name="articleName" id="name"><br/>
    文章封面:<input type="text" name="articleImage" id="image"><br/>
    文章内容简介:<input type="text" name="articleContent" id="content"><br/>
    所属上师id:<input type="text" name="guruId" id="guruid"><br/>

    <input type="button" value="提交" onclick="tijiao2()">
</div>